//
//  SunBankCardCell.m
//  Xspcf
//
//  Created by sunshine on 16/10/28.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "SunBankCardCell.h"
@interface SunBankCardCell()
{
    UILabel *_title;
    UILabel *_bankNum;
    UILabel *_phoneNum;
    UIImageView *_logo;
    UIImageView *_defaut;
}
@end
@implementation SunBankCardCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"cellID";
    SunBankCardCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[SunBankCardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        [cell creatSubviews];
    }
    return cell;
}

- (void)creatSubviews{
    self.backgroundColor = [UIColor clearColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.layer.cornerRadius = 5;
    self.clipsToBounds = YES;
    UIImageView *bg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, X(356), Y(112))];
    [self addSubview:bg];
    [bg lt_All:SunEdgesMake(0, 0, 0, 0) save:YES];
    bg.image = [Sun imageWithColorFrom:[HXColor colorWithHexString:@"E34D79"] To:[HXColor colorWithHexString:@"E95268"] Frame:bg.frame Direction:SunDirectionDiagonal0];
    bg.clipsToBounds = YES;
    bg.layer.borderColor = BLUE.CGColor;
    _logo = [[UIImageView alloc]init];
    [bg addSubview:_logo];
    [_logo lt_setSize:CGSizeMake(X(34), Y(34)) save:YES];
    [_logo lt_setTop:Y(15) to:nil save:YES];
    [_logo lt_setLeft:X(15) to:nil save:YES];
    _title = [[UILabel alloc]init];
    [bg addSubview:_title];
    [_title lt_YcenterTo:_logo save:YES];
    [_title lt_setLeft:X(8) to:_logo save:YES];
    _title.textColor = WHITE;
    _title.font = [UIFont systemFontOfSize:16];
    _bankNum = [[UILabel alloc]init];
    [bg addSubview:_bankNum];
    [_bankNum lt_leftEqual:_title save:YES];
    [_bankNum lt_setTop:Y(24) to:_logo save:YES];
    _bankNum.textColor = WHITE;
    _bankNum.font = [UIFont systemFontOfSize:19];
    _defaut = [[UIImageView alloc]init];
    [bg addSubview:_defaut];
    [_defaut lt_setSize:CGSizeMake(X(30), Y(25)) save:YES];
    [_defaut lt_topEqual:nil save:YES];
    [_defaut lt_setRight:X(15) to:nil save:YES];
    _phoneNum = [[UILabel alloc]init];
    [bg addSubview:_phoneNum];
    [_phoneNum lt_rightEqual:_defaut save:YES];
    [_phoneNum lt_setTop:Y(7) to:_defaut save:YES];
    _phoneNum.textColor = WHITE;
    _phoneNum.font = [UIFont systemFontOfSize:13];
    _defaut.image = [UIImage imageNamed:@"third_bank_default"];
    _defaut.hidden = YES;
}

- (void)setCellData:(NSDictionary *)data{
    if (![data isKindOfClass:[NSDictionary class]]) {
        return;
    }
    _title.text = [data objectForKey:@"bankname"];
    if ([[data objectForKey:@"is_default"]intValue] == 1){
        _defaut.hidden = NO;
    }else {
        _defaut.hidden = YES;
    }
    [_logo sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",KIMG,[data objectForKey:@"logo_yd"]]]];
    _phoneNum.text = [NSString stringWithFormat:@"手机尾号%@",[[data objectForKey:@"signphone"]substringFromIndex:7]];
    _bankNum.text = [NSString stringWithFormat:@"*** **** **** %@",[[data objectForKey:@"account"]substringFromIndex:[[data objectForKey:@"account"]length] - 4]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    if (selected) {
        self.layer.borderColor = BLUE.CGColor;
        self.layer.borderWidth = 2;
    }else {
        self.layer.borderWidth = 0;
    }
    
    // Configure the view for the selected state
}

@end
